import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  OneToMany,
} from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { GemBaseEntity } from "./gem-base.entity";
import { EquipmentGemSocketEntity } from "./equipment-gem-socket.entity";

@Entity("character_gem_inventory")
@ManualTimestamp()
export class CharacterGemInventoryEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { name: "character_id", comment: "角色ID" })
  characterId!: number;

  @Column("int", { name: "gem_base_id", comment: "宝石基础ID" })
  gemBaseId!: number;

  @Column("varchar", { length: 100, comment: "宝石名称（包含等级信息）" })
  name!: string;

  @Column("int", { default: 1, comment: "宝石等级" })
  level!: number;

  @Column("int", {
    name: "attribute_type",
    nullable: true,
    comment: "属性类型",
  })
  attributeType!: number;

  @Column("int", { name: "attribute_value", default: 0, comment: "属性值" })
  attributeValue!: number;

  @Column("tinyint", { default: 1, comment: "状态：0-已使用，1-正常" })
  status!: number;

  @Column("datetime", {
    name: "obtained_at",
    comment: "获得时间",
  })
  obtainedAt!: Date;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", {
    name: "updated_at",
    nullable: true,
    comment: "更新时间",
  })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity, (character) => character.gemInventories)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;

  @ManyToOne(() => GemBaseEntity, (gemBase) => gemBase.inventories)
  @JoinColumn({ name: "gem_base_id" })
  gemBase!: GemBaseEntity;

  // @OneToMany => EquipmentGemSocketEntity, (socket) => socket.gemInventory)
  // sockets!: EquipmentGemSocketEntity[];
}
